<template>
    <div class="wy-main business-car-manage">
      <a-row class="wy-main-title">
       <a-col :span="24">
        <p class="title-p">
          <a-divider class="title-vertical"  type="vertical" />
          <span class="title-span" >新闻资讯审核</span>
          <a-divider class="title-divider"  />
        </p>
      </a-col>
   </a-row>
     <div class="my-main-cont" style="margin-left: 30px">
       
        <a-form layout="inline">
          <a-form-item label="栏目">
            <a-select showSearch v-model="contentType"  style="min-width:174px" placeholder="全部">
              <a-select-option value="">全部</a-select-option>
               <a-select-option v-for="(itme,index) in list" :key="index" :value="itme.dictKey">
            {{itme.dictValue}}
          </a-select-option>
<!--               <a-select-option key="2" value="1">国际新闻</a-select-option>
              <a-select-option key="3" value="2" >国内新闻</a-select-option>
              <a-select-option key="4" value="3" >省内新闻</a-select-option>
              <a-select-option key="5" value="4" >行业焦点</a-select-option> -->
            </a-select>
          </a-form-item>
            <a-form-item  label="关键字">
          <a-input v-model="contentTxt"  placeholder='请输入关键字'   />
        </a-form-item>
        <a-button type="primary" style="margin-left: 10px;" @click="getcarSource">查询</a-button>
        <a-button style="margin-left: 14px;" @click="reset">重置</a-button>
         <a-button class="title-button" type="primary" style="float: right;min-width:80px;" @click="seeAllInfo()">批量审核</a-button>
      </a-form>
         <div class="wei_car_vehcle wei_new_list">
           <a-table :columns="columns" :rowKey="record => record.contentId" :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" @change="handleTableChange" :dataSource="cardata"  :pagination="pagination" :loading="loading" style="margin-top: 20px" >
        <!--     <span slot="contentType" slot-scope="text, record">
                <span v-if="record.contentType==1">国际新闻</span>
                <span v-if="record.contentType==2">国内新闻</span>
                <span v-if="record.contentType==3">省内新闻</span>
                <span v-if="record.contentType==4">行业焦点</span>
             </span> -->
               <span slot="releaseDateSplit" slot-scope="text, record">
                <span v-if="!!record.createTime">{{record.createTime.split(" ")[0]}}</span>

              </span>
              <span slot="operation" slot-scope="text, record">
                <a href="javascript:;" class="wei_warning"  v-if="record.approvalStatus==106" @click="edit(record)">待审核</a>
                <a href="javascript:;" class="wei_primary" v-if="record.approvalStatus==107" @click="edit(record)">审核通过</a>
                <a href="javascript:;" class="wei_danger" v-if="record.approvalStatus==108" @click="edit(record)">审核不通过</a>
               </span>
              
           </a-table>
          </div>
<!--           <div style="margin-top: -50px">
            <a-button @click="delAll">删除所选</a-button>
          </div> -->
     </div>
		 <a-modal title="新闻资讯审核" :visible="visible" @cancel="handleCancel" width="900px" :maskClosable='false' :footer="null" >
			  <news-add v-if="visible" :datail='datail' @cancel="handleCancel" :type='type'></news-add>
		 </a-modal>
      <a-modal title="批量审核" :visible="visibleAll"  @cancel="handleCancel"  width="900px" :maskClosable='false' :footer="null" >
       <news-add-all v-if="visibleAll" @cancel="handleCancel" :datailAll='datailAll'></news-add-all>
      </a-modal>
    </div>
</template>
<script>
import newsAdd from './NewsAdd'
import newsAddAll  from './NewsAddAll'
const columns = [{
		title: '栏目',
		dataIndex: 'contentTypeValue',
		key: 'contentTypeValue',
    // scopedSlots: {
    //   customRender: 'contentType'
    // },
	},{
    title: '标题',
    dataIndex: 'contentTitle',
    key: 'contentTitle',
  },{
    title: '浏览量',
    dataIndex: 'looksNum',
    key: 'looksNum',
  },{
		title: '提交日期',
		dataIndex: 'createTime',
		key: 'createTime',
      scopedSlots: {
      customRender: 'releaseDateSplit'
    },
	},
	{
		title: '操作',
		key: '0',
		scopedSlots: {
			customRender: 'operation'
		},
	}];

const rowSelection = {
  onChange: (selectedRowKeys, selectedRows) => {
    console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
  },
  onSelect: (record, selected, selectedRows) => {
    console.log(record, selected, selectedRows);
  },
  onSelectAll: (selected, selectedRows, changeRows) => {
    console.log(selected, selectedRows, changeRows);
  },
};
export default {
    
    data() {
        return {
			 type: '',
			 visible: false,
       visibleAll:false,
       contentType:'',
       list:[],
       contentCode:15,
       contentTxt:'',
       columns,
			 cardata:[],
			 datail: {},
       loading: false,
       licence: '',
       rowSelection,
       selectedRowKeys: [],
       pagination: {
       pageSizeOptions: ['10', '20', '30', '40', '100'],
       defaultCurrent: 1,
       defaultPageSize: 10,
       total:10,
       showSizeChanger: true,
       showTotal: (total, range) => `共 ${total} 条记录`
        },
        }
    }, 
    created() {
      this.getcarSource()
      this.getType(15)
		},
		components: {
			newsAdd,
      newsAddAll
		},
    methods: {
                 // 获取字典类型
      getType(type){
        this.$get('/info/commonDict', {
          dictType: type
        }).then((r) => {
          if(type == 3){
            console.log(r)
          }
          switch(type){
            case 15: this.list = r.data.data.rows; break;
          }
        })
      },
			//修改完毕刷新数据
				close(){
				this.visible = false
				this.getcarSource()
			},
      //选择参数
      seeAllInfo(){
        if(this.selectedRowKeys.length){
            this.visibleAll = true;
            let logIds = [];
           for(var i=0;i<this.selectedRowKeys.length;i++){
            logIds.push({"contentId":this.selectedRowKeys[i]})
           }
            this.datailAll = logIds;
          }else{
            this.$message.success('请选择需要审核的新闻!')
          }
      
      },
      onSelectChange (selectedRowKeys) {
          console.log('selectedRowKeys changed: ', selectedRowKeys);
          this.selectedRowKeys = selectedRowKeys
      },
			//审核货物信息
			edit(data){
				this.type = 'edit'
				this.visible = true
		    this.datail = data
			},
				// 关闭弹窗
			handleCancel(){
				this.visible = false
        this.visibleAll = false
         this.selectedRowKeys=[];
         this.getcarSource();
			},

			
			//删除
			delAll() {
				this.$confirm({
					title: '确定删除所选中的记录？',
					content: '当您点击确定按钮后，这些记录将会被彻底删除',
					centered: true
				})

			},
      //重置
      reset () {
				this.pagination.defaultCurrent = 1;
				this.contentType = ''
        this.contentTxt = ''
				this.getcarSource();
			},
			
			//获取车源信息
				getcarSource(params={}){
				this.loading = true
				// params.licence = this.licence
         if(this.contentType!='全部'){
            params.contentType = this.contentType
        }
        params.contentTxt = this.contentTxt
        params.contentCode = this.contentCode
				params.pageSize = this.pagination.defaultPageSize
				params.pageNum = this.pagination.defaultCurrent
				// params.licence= this.licence
				this.$get('/content/content', params).then((r) => {
					this.loading = false
					this.cardata = r.data.data.rows
          this.pagination.total = r.data.data.total
				})
			},
            // 表格排序 分页 筛选事件
      handleTableChange(pagination, filters, sorter) {
         this.pagination.defaultPageSize = pagination.pageSize
         this.pagination.defaultCurrent  = pagination.current
         this.getcarSource();
        // this.getcarSource({
        //   ...this.queryParams
        // })
      },
    }
}
</script>
<style lang="less">
.title-button{
    float:right;

}
</style>
